package com.samuel.basics.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * <p>自动填充功能</p>
 *
 * @author aneng huang
 * @since 2020-11-30 11:40:46
 */
@Component
public class MyBatisPlusMetaObjectHandlerConfig implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "deleted", ()->1, Integer.class);
        this.strictInsertFill(metaObject, "createDate", LocalDateTime::now, LocalDateTime.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // 起始版本 3.3.3(推荐)
        this.strictUpdateFill(metaObject, "modifyDate", LocalDateTime::now, LocalDateTime.class);
    }
}
